package org.hhttp.cookie;

import java.util.HashMap;
import java.util.Map;

import org.hhttp.core.Cookie;

public class DefaultCookie implements Cookie {

	private static final long serialVersionUID = 6987792077746202938L;

	private Map<String, Object> map;
	
	public DefaultCookie(){
		this.map = new HashMap<String, Object>();
	}

	public Object getCookie(String key) {
		if (map == null) {
			return null;
		} else {
			return map.get(key);
		}
	}

	public void setCookie(String key, Object value) {
		if (map == null) {
			map = new HashMap<String, Object>();
		}
		map.put(key, value);
	}

	@Override
	public void reset() {
		if(map != null){
			map.clear();
		}
	}
	
	@Override
	public String toString() {
		if(map.size() <= 0){
			return null;
		}
		StringBuilder sb = new StringBuilder();
		for (Map.Entry<String, Object> entry: map.entrySet()) {
			sb.append(" " + entry.getKey() + "=" + entry.getValue() + ";");
		}
		sb.substring(0, sb.length() - 1);
		return sb.toString();
	}

}
